#include <iostream>
#include <vector>
#include <string>


int Split(const std::string& str ,const std::string& sep ,std::vector<std::string>& arry)
{
  int count = 0;
  size_t pos = 0;
  size_t idx = 0;
  while (1)
  {
    pos = str.find(sep , idx);
    if (pos == std::string::npos)
    {
      break;
    }
    if (pos == idx)
    {
      idx = pos + sep.size();
      continue;
    }
    std::string tmp = str.substr(idx , pos - idx);
    arry.push_back(tmp);
    count++;
    idx = pos + sep.size();
  }

  if (idx < str.size())
  {
    arry.push_back(str.substr(idx));
    count++;
  }

  return count;
}


int main()
{
  std::string str  = "abc dga  aaa dad ";
  std::vector<std::string> arry;
  Split(str ," " , arry);
  for (auto x : arry)
  {
    std::cout << x << std::endl;
  }
  return 0;
}
